let $db := doc("xp") 
let $xp := $db/ranking/xps//xp 
return 	
	(:Pour toutes les xps :)
	for $x in $xp 
	return  
		(:Pour toutes les requêtes de chaque xp on ajout l'xp:)
		insert node 
			<xp> 
				{$x/@id}
				{
					(:Pour chaque reqête d'une xp:)
					for $req in $x//req 
					return 
						<notation id="{data($req/nom/text())}"> 
						{
							for $user in $db/ranking/globalResults/resultsByXp/xp[@id = $x/@id]//user
							order by number($user/notation[nom/text() = $req/nom/text()]/points) descending
							return 
								<user>
									<name>{$user/name/text()}</name>
									<points>{$user/notation[nom/text() = $req/nom/text()]/points/text()}</points>
									<rank/>
									{$user/notation[nom/text() = $req/nom/text()]/badges}
								</user>
						}
						</notation>
				}
			</xp>
		into $db/ranking/rankings/notationRanking
				
		
		